﻿namespace Webinator.ExtensionMethods
{
    using System;

    /// <summary>
    /// Useful extension methods.
    /// </summary>
    public static class BooleanExtensions
    {
        /// <summary>
        /// Asserts that the specified boolean value is true.
        /// </summary>
        /// <param name="value">The boolean value to assert.</param>
        /// <param name="message">The exception message.</param>
        public static void AssertTrue(this bool value, string message)
        {
            if (!value)
            {
                throw new Exception(string.IsNullOrWhiteSpace(message) ? "Assertion failed: expected <true> but was <false>." : message);
            }
        }

        /// <summary>
        /// Asserts that the specified boolean value is true.
        /// </summary>
        /// <param name="value">The boolean value to assert.</param>
        public static void AssertTrue(this bool value)
        {
            AssertTrue(value, string.Empty);
        }

        /// <summary>
        /// Asserts that the specified boolean value is false.
        /// </summary>
        /// <param name="value">The boolean value to assert.</param>
        /// <param name="message">The exception message.</param>
        public static void AssertFalse(this bool value, string message)
        {
            if (value)
            {
                throw new Exception(string.IsNullOrWhiteSpace(message) ? "Assertion failed: expected <false> but was <true>." : message);
            }
        }

        /// <summary>
        /// Asserts that the specified boolean value is false.
        /// </summary>
        /// <param name="value">The exception message.</param>
        public static void AssertFalse(this bool value)
        {
            AssertFalse(value, string.Empty);
        }
    }
}
